package com.bridgeintelligent.tag.customer.service;

import com.bridgeintelligent.tag.customer.entity.CustomersPage;
import com.bridgeintelligent.tag.customer.mapper.IssueLogMapper;
import com.bridgeintelligent.tag.customer.model.IssueLogQueryModel;
import com.bridgeintelligent.tag.customer.vo.IssueLogVO;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @description
 * @author: grp 2021-03-01 13:46
 **/
@Service
@Slf4j
@AllArgsConstructor
public class IssueLogServiceImpl implements IIssueLogService {

    private final IssueLogMapper issueLogMapper;
    @Override
    public CustomersPage<IssueLogVO> list(IssueLogQueryModel model) {
        if (StringUtils.isNotEmpty(model.getStart())) {
            model.setStart(model.getStart() + " 00:00:00");
        }
        if (StringUtils.isNotEmpty(model.getEnd())) {
            model.setEnd(model.getEnd() + " 23:59:59");
        }
        Page page = PageHelper.startPage(model.getPageNumber(), model.getPageSize());
        List<IssueLogVO> list = issueLogMapper.findList(model);
        return new CustomersPage<IssueLogVO>().setContent(list).setTotalPages(page.getPages()).setRequestPager(model.getPageNumber())
                .setSize(model.getPageSize()).setTotalElements(page.getTotal());
    }

    @Override
    public boolean runCount(String taskId) {
        Integer count = issueLogMapper.runCount(taskId);
        if (count > 0){
            return false;
        }
        return true;
    }


}
